package com.iwhalecloud.citybrain.flow.platform.manager.domain.enums;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @author lilh
 * @date 2019-04-25 14:09
 */
public enum MsgTypeEnum {

    PROCESS_TIMEOUT_NOTICE("PROCESS_TIMEOUT", "FLOW", "流程超时通知"),

    PROCESS_WARNING_NOTICE("PROCESS_WARNING", "FLOW", "流程预警通知"),

    TASK_TIMEOUT_NOTICE("TASK_TIMEOUT", "NODE", "任务超时通知"),

    TASK_WARNING_NOTICE("TASK_WARNING", "NODE", "任务预警通知"),

    TASK_START_NOTICE("TASK_START", "NODE", "任务开始通知"),
    TASK_COMPLETED_NOTICE("TASK_COMPLETED", "NODE", "任务完成通知"),
    TASK_CLAIM_NOTICE("TASK_CLAIM", "NODE", "任务签收通知"),
    TASK_DEPLAY_NOTICE("TASK_DEPLAY", "NODE", "任务延期通知"),
    TASK_ADDSIGNTASK_NOTICE("TASK_ADDSIGNTASK", "NODE", "任务加签通知"),
    TASK_DELSIGNTASK_NOTICE("TASK_DELSIGNTASK", "NODE", "任务减签通知"),
    TASK_TRUN_NOTICE("TASK_TRUN", "NODE", "任务转办通知"),
    TASK_REMIND("TASK_REMIND", "NODE", "任务催办通知"),
    PROCESS_INSTANCE_RECALL("PROCESS_INSTANCE_RECALL", "NODE", "任务撤回通知");

    private String code;

    private String type;

    private String description;

    private static Map<String, Map<String, String>> codeToDesc = new HashMap<>();

    static {

        Arrays.asList(values()).forEach(item -> {
            Map<String, String> value = null;
            if (Objects.isNull(codeToDesc.get(item.getType()))) {
                codeToDesc.put(item.getType(), new HashMap<>());
            }
            codeToDesc.get(item.getType()).put(item.getCode(), item.getDescription());
        });
    }

    MsgTypeEnum(String code, String type, String description) {
        this.code = code;
        this.type = type;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public static String getDescrByCode(String code) {
        for (Map.Entry<String, Map<String, String>> mapEntry : codeToDesc.entrySet()) {
            if (mapEntry.getKey().equalsIgnoreCase(code)) {
                Map<String, String> value = mapEntry.getValue();
                for (String s : value.keySet()) {
                    if (s.equalsIgnoreCase(code)) {
                        return value.get(s);
                    }
                }
            }
        }
        return null;
    }

    public static Map<String, Map<String, String>> getCodeToDesc() {
        return codeToDesc;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public static void setCodeToDesc(Map<String, Map<String, String>> codeToDesc) {
        MsgTypeEnum.codeToDesc = codeToDesc;
    }
}
